<template>
  <div class="color-grey">
    <el-form
      ref="form"
      :model="loginForm"
      label-width="80px"
      class="form-signin "
    >
      <h1>请登录!</h1>
      <div>
        <i class="fa fa-user-o fa-5x adminimg" aria-hidden="true"></i>
      </div>
      <el-form-item label="登录账号">
        <el-input v-model="loginForm.userName" placeholder="您的ID"></el-input
      ></el-form-item>
      <el-form-item label="登录密码">
        <el-input
          type="password"
          v-model="loginForm.password"
          placeholder="您的密码"
          required=""
        ></el-input
      ></el-form-item>

      <el-button style="width: 100%" type="primary" @click="login()">
        登录
      </el-button>
      <p>
        <el-link @click="forgetPass" style="float: left" type="success"
          >忘记密码</el-link
        ><el-link @click="gotoSignup" style="float: right">立即注册</el-link>
      </p>
    </el-form>
  </div>
</template>

<script>
export default {
  name: "AdminLogin",
  data() {
    return {
      loginForm: {

        userName: "",
        password: ""
      }
    };
  },
  methods: {
    login() {
      this.$axios.post("/user/login", this.loginForm).then(res => {
        console.log(res.data);
        if (res.data.success) {
          localStorage.setItem(`id`, this.loginForm.userName);
          localStorage.setItem(`password`, this.loginForm.password);
          this.$router.push({
            name: "Admin",
            params: { id: this.loginForm.userName }
          });
        } else {
          this.$message.error("登录失败");
          localStorage.removeItem("id");
          localStorage.removeItem("pass");
        }
      });
    },
    forgetPass() {},
    gotoSignup() {
      this.$router.push({
        name: "Signup"
      });
    }
  }
};
</script>

<style scoped>
/*设置背景颜色*/

.form-signin {
  max-width: 400px;
  padding: 15px 35px 45px;
  margin: 0 auto;
  background-color: #ffffff;
}

.color-grey {
  background-color: #eee;
  height: 100%;
}
</style>
